package com.jia.explore.dynamicprogramming.knapsack;

import java.util.Scanner;

/**
 * @program: Leetcode
 * @description: 01背包的变种  https://www.acwing.com/problem/content/9/
 * @author: STU756
 * @create: 2020-08-19 13:26
 */
public class Dy_GroupBackpack {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int v = scanner.nextInt();
        int N = 110;
        int[] vs = new int[N];
        int[] ws = new int[N];
        int[] f = new int[N];
        for(int i = 1; i <= n; i++) {
            int s = scanner.nextInt();
            for(int k = 1; k <= s; k++) {
                vs[k] = scanner.nextInt();
                ws[k] = scanner.nextInt();
            }
            for(int j = v; j >= 0; j--) {
                for(int k = 1; k <= s; k++) {
                    if(j >= vs[k])
                        f[j] = Math.max(f[j], f[j-vs[k]] + ws[k]);
                }
            }
        }
        System.out.println(f[v]);
    }
}
